#include	<unistd.h>
#include	<stdlib.h>
#include	<sys/types.h>
#include	<sys/stat.h>
#include	<pwd.h>
#include	<time.h>
#include	"my.h"

int		fill_list(t_list **list, struct stat stat, struct dirent *d)
{
  t_list	*new_list;

  new_list = malloc(sizeof(*new_list)); 
  if (new_list == NULL)
    my_put_error("Malloc function failed in fill_list\n");
  new_list->name = d->d_name;
  new_list->uid = getpwuid(stat.st_uid)->pw_name;
  new_list->gid = getpwuid(stat.st_gid)->pw_name;
  new_list->size = stat.st_size;
  new_list->ino = stat.st_ino;
  //new_list->month = ctime(stat.st_ctime)->tm_mon;
  new_list->next = *list;
  *list = new_list;
  return (0);
}

void		show_l(t_list *list)
{ 
  t_list	 *tmp;

  tmp = list;
  while (tmp != NULL)
    {
      my_put_nbr(tmp->ino);
      my_putchar(' ');
      my_putstr(tmp->uid);
      my_putchar(' ');
      my_putstr(tmp->gid);
      my_putchar(' ');
      my_put_nbr(tmp->size);
      my_putchar(' ');
      my_putstr(tmp->name);
      my_putchar('\n');
      tmp = tmp->next;
    } 
}

void		show_a(t_list *list)
{

}

int		my_showlist(t_list *list, int opt)
{
  if (opt == 1)
    {
      show_l(list);
      return (1);
    }
  else if (opt == 2)
    {
      show_a(list);
      return (1);
    }
  return (0);
}
